﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing;

namespace C12_Ex03_Shaked_032675316_Itay_032511057
{
    public enum ResponsivePictureStates
    {
        IN,
        OUT,
        CLICKED
    }

    public abstract partial class ResponsivePicture : PictureBox
    {
        protected IControlPainter m_OnHoverEffect;
        protected ResponsivePictureStates m_State;

        public ResponsivePicture()
        {
            m_State = ResponsivePictureStates.OUT;
            InitializeComponent();
        }

        protected override void OnPaint(PaintEventArgs pe)
        {
            base.OnPaint(pe);

            AdditionalDrawings(pe);

            if (this.Enabled && m_State == ResponsivePictureStates.IN)
            {
                m_OnHoverEffect.Paint(pe);
            }

            if (this.Enabled && m_State == ResponsivePictureStates.CLICKED)
            {
                DrawWhenClicked(pe);
            }
        }

        protected abstract void AdditionalDrawings(PaintEventArgs pe);

        protected abstract void DrawWhenClicked(PaintEventArgs pe);

        protected override void OnMouseMove(MouseEventArgs e)
        {
            base.OnMouseMove(e);
            m_State = ResponsivePictureStates.IN;
            Invalidate();
        }

        protected override void OnMouseDown(MouseEventArgs e)
        {
            base.OnMouseDown(e);
            m_State = ResponsivePictureStates.CLICKED;
            Invalidate();
        }

        protected override void OnClick(EventArgs e)
        {
            base.OnClick(e);
            m_State = ResponsivePictureStates.CLICKED;
            Invalidate();
        }

        protected override void OnMouseUp(MouseEventArgs e)
        {
            base.OnMouseUp(e);
            if (e.X >= this.Left && e.X <= this.Left + this.Width && e.Y >= this.Top && e.Y <= this.Top + this.Height)
            {
                m_State = ResponsivePictureStates.IN;
            }
            else
            {
                m_State = ResponsivePictureStates.OUT;
            }

            Invalidate();
        }

        protected override void OnMouseLeave(EventArgs e)
        {
            base.OnMouseLeave(e);
            m_State = ResponsivePictureStates.OUT;
            Invalidate();
        }
    }
}
